<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./site/public/logout.php, $Author:  $ */
$oReq =& App::getRequest();
$oTpl =& App::getTemplate();
$oDb =& Database::get();

$iChat = $oDb->getField("SELECT COUNT(*) FROM " . App::getT('chat_online') . " WHERE userid = '" . App::getUser('id') . "' AND time != 0");
$iIm = $oDb->getField("SELECT COUNT(*) FROM " . App::getT('msg_online') . " WHERE userid = '" . App::getUser('id') . "' AND time != 0");

$sJavaScript = '';

if ($iChat || $iIm)
{
	$sJavaScript .= '<script type="text/javascript">
	var sDisplayIds = new Array(\'social_bookmarks\');
	window.onload = clicktoHideAll;';
}

if ($iChat)
{
	$oDb->update(App::getT('chat_online'), array('time' => 0), "userid = '" . App::getUser('id') . "'");
	$sJavaScript .= 'chatWin = window.open("", "chat", "width=1, height=1");';
	$sJavaScript .= 'chatWin.close();';	
}

if ($iIm)
{
	$oDb->update(App::getT('msg_online'), array('time' => 0), "userid = '" . App::getUser('id') . "'");
	$sJavaScript .= 'shoutboxWin = window.open("", "messenger", "width=1, height=1");';
	$sJavaScript .= 'shoutboxWin.close();';	
}

if ($iChat || $iIm)
{
	$sJavaScript .= '</script>';	
}

if (isset($_SESSION['display_extra_header']))
{
	$oTpl->assignSrc('sExtraHeader', base64_decode($_SESSION['display_extra_header']));
	unset($_SESSION['display_extra_header']);
}

if ( !$oReq->get('completed') )
{
	$oSrvSec = App::getModuleService('Account', 'Security');
	$oSrvSec->logout();
	if ($sJavaScript)
	{
		$_SESSION['display_extra_header'] = base64_encode($sJavaScript);
	}
	App::gotoUrl('public.logout', array('completed' => 'true'));
}

if ($oReq->get('multi') == 'true')
{
	$oTpl->assignSrc('bMulti', true);
}

?>